<template>
  <div class="home">
    <van-nav-bar title="首页" :fixed="true"></van-nav-bar>
    <van-search
      class="search"
      v-model="value"
      placeholder="搜索商品"
      shape="round"
      @focus="toSearch"
    />

    <van-swipe class="banner" :autoplay="3000">
      <van-swipe-item v-for="(item, index) in banner" :key="index">
        <img v-lazy="item.bannerImg" />
      </van-swipe-item>
    </van-swipe>

    <div class="best-sellers">
      <div class="bs-title">
        <span>热卖推荐</span>
      </div>
      <div class="commodity">
        <div
          class="bs-item"
          v-for="(item, index) in isHot"
          :key="index"
          @click="toDetail(item.pid)"
        >
          <span class="hot">hot</span>
          <img :src="item.largeImg" alt="" />
          <p class="name">{{ item.name }}</p>
          <p class="enname">{{ item.enname }}</p>
          <p class="price">&yen;{{ item.price }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      value: "",
      banner: [],
      isHot: [],
    };
  },

  created() {
    this.getBanner();
    this.getisHot();
  },

  methods: {
    toSearch(){
      this.$router.push({name:'Search'})
    },
    getBanner() {
      this.axios({
        method: "get",
        url: "http://www.kangliuyong.com:10002/banner",
        params: {},
      })
        .then((result) => {
          this.banner = result.data.result;
        })
        .catch((err) => {

        });
    },
    getisHot() {
      this.axios({
        method: "get",
        url: "/typeProducts",
        params: {
          key: "isHot",
          value: 1,
        },
      })
        .then((result) => {
          this.isHot = result.data.result;
        })
        .catch((err) => {

        });
    },
    toDetail(pid) {
      this.$router.push({ name: "Detail", params: { pid } });
    },
  },
};
</script>

<style lang="less" scoped>
.home {
  padding-top: 76px;
  .van-nav-bar--fixed{
    padding-top: 30px;
    background-color: #0022ab;
  }
  /deep/.van-nav-bar__title{
    color: #fff;
  }
  .banner {
    width: 100%;
    height: 279px;
    img {
      width: 100%;
    }
  }
  .best-sellers {
    margin-bottom: 60px;
    .bs-title {
      width: 100%;
      height: 70px;
      background-color: #fff;
      margin: 10px 0;
      display: flex;
      align-items: center;
      span {
        font-size: 16px;
        background-color: #0022ab;
        color: #fff;
        padding: 10px 20px;
        border-radius: 0 20px 0 0;
      }
    }
    .commodity {
      display: flex;
      justify-content: space-around;
      flex-wrap: wrap;
      .bs-item {
        width: 160px;
        background-color: #fff;
        padding: 10px;
        border-radius: 10px;
        position: relative;
        margin-bottom: 10px;
        span {
          background-color: #0022ab;
          color: #fff;
          padding: 5px;
          position: absolute;
          left: 20px;
          border-radius: 0 0 5px 5px;
        }
        img {
          width: 100%;
          border-radius: 8px;
          margin-bottom: 10px;
        }
        .name {
          font-size: 15px;
          color: #666;
          margin-bottom: 5px;
        }
        .enname {
          font-size: 12px;
          color: #999;
          margin-bottom: 10px;
          height: 14px;
          overflow: hidden;
        }
        .price {
          font-size: 15px;
          color: #0022ab;
          font-weight: 600;
        }
      }
    }
  }
}
</style>